package com.supermarket.web.controller.supermarket;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.supermarket.business.domain.SupermarketWarehouseManager;
import com.supermarket.business.dto.SupermarketWarehouseManagerDTO;
import com.supermarket.business.vo.SupermarketWarehouseManagerVO;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.supermarket.common.annotation.Log;
import com.supermarket.common.core.controller.BaseController;
import com.supermarket.common.core.domain.AjaxResult;
import com.supermarket.common.enums.BusinessType;
import com.supermarket.business.service.ISupermarketWarehouseManagerService;
import com.supermarket.common.utils.poi.ExcelUtil;
import com.supermarket.common.core.page.TableDataInfo;

/**
 * 仓库管理员Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/supermarket/manager")
public class SupermarketWarehouseManagerController extends BaseController
{
    @Resource
    private ISupermarketWarehouseManagerService sysWarehouseManagerService;

    /**
     * 查询仓库管理员列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:manager:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketWarehouseManagerDTO supermarketWarehouseManagerDTO)
    {
        startPage();
        SupermarketWarehouseManager supermarketWarehouseManager = new SupermarketWarehouseManager();
        BeanUtils.copyProperties(supermarketWarehouseManagerDTO, supermarketWarehouseManager);
        List<SupermarketWarehouseManager> list = sysWarehouseManagerService.selectSysWarehouseManagerList(supermarketWarehouseManager);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理员列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:manager:export')")
    @Log(title = "仓库管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketWarehouseManager supermarketWarehouseManager)
    {
        List<SupermarketWarehouseManager> list = sysWarehouseManagerService.selectSysWarehouseManagerList(supermarketWarehouseManager);
        ExcelUtil<SupermarketWarehouseManager> util = new ExcelUtil<SupermarketWarehouseManager>(SupermarketWarehouseManager.class);
        util.exportExcel(response, list, "仓库管理员数据");
    }

    /**
     * 获取仓库管理员详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:manager:query')")
    @GetMapping(value = "/{managerId}")
    public AjaxResult getInfo(@PathVariable("managerId") Long managerId)
    {
        return success(sysWarehouseManagerService.selectSysWarehouseManagerVOByManagerId(managerId));
    }

    /**
     * 新增仓库管理员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:manager:add')")
    @Log(title = "仓库管理员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketWarehouseManagerDTO supermarketWarehouseManagerDTO)
    {
        SupermarketWarehouseManager supermarketWarehouseManager = new SupermarketWarehouseManager();
        BeanUtils.copyProperties(supermarketWarehouseManagerDTO, supermarketWarehouseManager);
        return toAjax(sysWarehouseManagerService.insertSysWarehouseManager(supermarketWarehouseManager));
    }

    /**
     * 修改仓库管理员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:manager:edit')")
    @Log(title = "仓库管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketWarehouseManagerDTO supermarketWarehouseManagerDTO)
    {
        SupermarketWarehouseManager supermarketWarehouseManager = new SupermarketWarehouseManager();
        BeanUtils.copyProperties(supermarketWarehouseManagerDTO, supermarketWarehouseManager);
        return toAjax(sysWarehouseManagerService.updateSysWarehouseManager(supermarketWarehouseManager));
    }

    /**
     * 删除仓库管理员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:manager:remove')")
    @Log(title = "仓库管理员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{managerIds}")
    public AjaxResult remove(@PathVariable Long[] managerIds)
    {
        return toAjax(sysWarehouseManagerService.deleteSysWarehouseManagerByManagerIds(managerIds));
    }


    /**
     * 获取当前登入用户的id
     */
    @GetMapping("/getSysId")
    public AjaxResult getSysId(){
        String nowSysId = sysWarehouseManagerService.getNowSysId();
        //获取当前员工的id
        return AjaxResult.success(nowSysId);
    }
}
